import gradio as gr
from LV60DAO import LV60_Cal
from LV70DAO import LV70_Cal
from LV80DAO import LV80_Cal

class Main():

    def __init__(self,cal_60,cal_70,cal_80):
        self.cal_60 = cal_60
        self.cal_70 = cal_70
        self.cal_80 = cal_80

    def run(self,):
        visible= False
        with gr.Blocks(css="footer {visibility: hidden}") as webui:
            with gr.Tab("芯核计算V1.4"):
                with gr.Column():
                    with gr.Row():
                        small_heal = gr.Textbox(label="小生命", type="text")
                        small_atk = gr.Textbox(label="小攻击", type="text")
                        small_def = gr.Textbox(label="小防御", type="text")
                        crit = gr.Textbox(label="暴击", type="text")
                        crit_injuy = gr.Textbox(label="暴击伤害", type="text")
                        big_heal = gr.Textbox(label="大生命", type="text")
                        big_atk = gr.Textbox(label="大攻击", type="text")
                        big_def = gr.Textbox(label="大防御", type="text")
                        weakness_increases_damage = gr.Textbox(label="虚弱增伤", type="text")
                        oath_increases_injury = gr.Textbox(label="誓约增伤", type="text")

                with gr.Column():
                    xinhe_level = gr.Textbox(label="芯核等级", type="text")
                    Level_select = gr.Dropdown(label="选择计算等级", choices=["60级", "70级", "80级"], value="60级")
                    clean_button = gr.Button("清空")
                    cal_button = gr.Button("计算")



                with gr.Column():
                    ci_tiao_shu_pan_duan = gr.Textbox(label="词条数判断", type="text",visible=visible)
                    shuangsheng_jisuan = gr.Textbox(label="双生计算", type="text",visible=visible)
                    shuanggong_jisuan = gr.Textbox(label="双攻计算", type="text",visible=visible)
                    shuangfang_jisuan = gr.Textbox(label="双防计算", type="text",visible=visible)

                with gr.Column():
                    with gr.Row():
                        zhuguang_shenhai = gr.Textbox(label="逐光/深海")
                        xianzhi_moye = gr.Textbox(label="先知/末夜")
                        shendian = gr.Textbox(label="神殿")
                        cankaozhi = gr.Textbox(label="总强化词条数参考")
                        cankaozhi_str = gr.Textbox(label="双攻防生0级核结果")
                        xing_zhuguang = gr.Textbox(label="星-逐光",visible=visible)
                        li_xianzhi = gr.Textbox(label="黎-先知",visible=visible)
                        yu_shenhai = gr.Textbox(label="鱼-深海",visible=visible)
                        yu_shendian = gr.Textbox(label="鱼-神殿",visible=visible)

            cal_button.click(fn=self.select_LV_and_run,
                             inputs=[Level_select,small_heal, small_atk, small_def, crit, crit_injuy, big_heal, big_atk, big_def,
                                     weakness_increases_damage, oath_increases_injury, xinhe_level]
                             , outputs=[ci_tiao_shu_pan_duan,shuangsheng_jisuan,shuanggong_jisuan,shuangfang_jisuan,xing_zhuguang,li_xianzhi,yu_shenhai,yu_shendian,zhuguang_shenhai,xianzhi_moye,shendian,cankaozhi,cankaozhi_str])

            clean_button.click(
                fn=self.clear_all,
                inputs=[],
                outputs=[
                    small_heal, small_atk, small_def, crit, crit_injuy,
                    big_heal, big_atk, big_def, weakness_increases_damage,
                    oath_increases_injury, xinhe_level
                ]
            )

        webui.launch(server_name = '0.0.0.0',server_port=7005,share=True)

    def select_LV_and_run(self,Level_select,small_heal, small_atk, small_def, crit, crit_injuy, big_heal, big_atk, big_def,
                                 weakness_increases_damage, oath_increases_injury, xinhe_level):

        if Level_select == "60级":
            return self.cal_60.run(small_heal, small_atk, small_def, crit, crit_injuy, big_heal, big_atk, big_def,
                                     weakness_increases_damage, oath_increases_injury, xinhe_level)
        if Level_select == "70级":
            return self.cal_70.run(small_heal, small_atk, small_def, crit, crit_injuy, big_heal, big_atk, big_def,
                                     weakness_increases_damage, oath_increases_injury, xinhe_level)
        if Level_select == "80级":
            return self.cal_80.run(small_heal, small_atk, small_def, crit, crit_injuy, big_heal, big_atk, big_def,
                                     weakness_increases_damage, oath_increases_injury, xinhe_level)

    def clear_all(self):
        return "", "", "", "", "", "", "", "", "", "", ""

if __name__ == "__main__":
    cal_60 = LV60_Cal()
    cal_70 = LV70_Cal()
    cal_80 = LV80_Cal()
    main = Main(cal_60,cal_70,cal_80)
    main.run()